<template>
    <div class="loginPageSty">
        <div class="name">
            户享邦户型管理平台
        </div>
        <div class="formSty">
            <div class="iptItem marginTop">
                <img src="@/assets/img/user.png" class="imgSty">
                <input placeholder="请输入手机号" v-model="form.userName" class="iptSty" />
            </div>
            <div class="iptItem">
                <img src="@/assets/img/password.png" class="imgSty">
                <input placeholder="请输入密码" type="password" v-model="form.password" class="iptSty" />
            </div>
            <div class="iptItem">
                <input placeholder="请输入验证码" type="verifyCode" v-model="form.verifyCode" class="iptSty addIptSty" />
                <el-button @click="getCode">{{ codeTxt }}</el-button>
            </div>
            <el-button class="btnSty" @click="goRegister">注册</el-button>
            <div class="forgetSty" @click="goLogin">去登录</div>
        </div>


    </div>
</template>
<script lang="ts" setup>
import { reactive, ref } from "vue";
import { useRouter } from 'vue-router'
import { getCodeApi, registerApi } from '@/api/index/index';
import { ElMessage } from "element-plus";
const router = useRouter()
const form = reactive({
    userName: '',
    password: '',
    verifyCode: ''
})
const codeTxt = ref<any>('获取验证码')
function goLogin() {
    router.push({ path: '/login' })
}
const goRegister = () => {
    if (form.password == '' || form.userName == '' || form.verifyCode == '') {
        ElMessage.warning('注册信息不完整')
        return
    }
    registerApi(form).then((res: any) => {
        if (res.status == 200) {
            ElMessage.success('注册成功，请登录')
            router.push({ path: '/login' })
        }
    })
}
const getCode = () => {
    // if (codeTxt.value !== '获取验证码') {
    //     ElMessage.warning(`${codeTxt.value}秒后重试`)
    //     return
    // }
    // if (form.userName == '') {
    //     ElMessage.warning('请输入手机号')
    //     return
    // }
    const reg = 11 && /^((13|14|15|16|17|18|19)[0-9]{1}\d{8})$/;
    if (!reg.test(form.userName)) {
        ElMessage.warning('手机号不正确')
        return
    }
    // codeTime()

    let params = {
        userName: form.userName
    }
    getCodeApi(params).then((res: any) => {
        codeTxt.value = res.data.verifyCode
    })
}
</script>
  
<style scoped>
.addIptSty {
    width: 65%;
    margin-left: 12px;
}

.loginPageSty {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    background: url("../../assets/img/login.png") 100% / cover no-repeat;
}

.name {
    font-size: 46px;
    color: #fff;
    margin-top: 154px;
    width: 578px;
    height: 110px;
    text-align: center;
}

.formSty {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-direction: column;
    /* width: 716px;
    height: 654px; */
    padding: 40px 80px;
    border: 1px solid #07D2E4;
    border-radius: 12px;
    /* 背景图不对 透明部分不对称 */
    /* background: url("../../assets/img/form_bg.png") 100% / cover no-repeat; */
}


.iptItem {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    width: 374px;
    height: 64px;
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: rgba(0, 0, 0, 0.1);
    margin-bottom: 50px;
}


.imgSty {
    width: 32px;
    margin: 0 10px;
}

.iptSty {
    background-color: rgba(0, 0, 0, 0.1);
    border: none;
    color: #fff;
}

.iptSty:focus {
    outline: none;
}

.btnSty {
    width: 374px;
    height: 64px;
    background-color: #07D2E4;
    border: none;
    color: #fff;
    font-size: 28px;
    margin-top: 10px;
}

.forgetSty {
    font-size: 21px;
    color: #0ADFEF;
    margin-top: 20px;
}

.marginTop {
    margin-top: 6px;
}
</style>